<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Bootloader Development</title>
		<link rel="stylesheet" type="text/css" href="./images/style.css">
	</head>
	
	<body>
		<header class="banner">
			<h1>PIC24系列MCU 串口自举程序（Bootloader）开发</h1>
		</header>
		
		<main>
			<section>
				<h2>1. 简介</h2>
				<article>
					<p>本示例用于演示如何基于MCC环境快速开发PIC24系列MCU(PIC24FJ64GU205)的串口自举程序。</p>
				</article>
			</section>
			
			<section>
				<h2>2. 工具</h2>
				<article>
					<header>
					<h3>2.1. 软件开发环境</h3>
					</header>
					<p>相关软件开发版本情况说明如下。</p>
					<ul>
					<li><a href="https://www.microchip.com/mplabx" target="_blank">Microchip MPLAB® xIDE version 5.50 or newer</a></li>
					<li><a href="https://www.microchip.com/en-us/development-tools-tools-and-software/mplab-xc-compilers" target="_blank">Microchip MPLAB® XC16 C compiler version 1.70 or newer</a></li>
					<li><a href="https://www.microchip.com/SWLibraryWeb/product.aspx?product=16-bit-Bootloader" target="_blank">Unified Bootloader Host Application v1.18.0 or newer</a></li>
					<li><a href="https://www.microchip.com/en-us/development-tools-tools-and-software/embedded-software-center/mplab-code-configurator" target="_blank">Microchip MPLAB® Code Configurator (MCC) version 4.2.1 (with core v5.2.4) or newer</a></li>
					<li><a href="https://www.microchip.com/en-us/development-tools-tools-and-software/embedded-software-center/mplab-code-configurator" target="_blank">Microchip MPLAB® Code Configurator (MCC) Device Libraries PIC24 / dsPIC33 / PIC32MM MCUs version 1.170.0 or newer</a></li>
					<li><a href="https://www.microchip.com/en-us/development-tools-tools-and-software/embedded-software-center/mplab-code-configurator" target="_blank">Microchip 16-bit Bootloader version 1.18.4 or newer</a></li>
					<li><a href="https://packs.download.microchip.com/" target="_blank">Microchip PIC24F-GP-GU Series Device Support version 1.0.59 or newer</a></li>
					</ul>
				</article>
				<article>
					<header>
					<h3>2.2. 硬件开发环境</h3>
					</header>
					<p>该例程基于如下硬件开发。</p>
					<ul>
					<li><a href="https://www.microchip.com/en-us/development-tool/EV10K72A" target="_blank">PIC24FJ64GU205 CURIOSITY NANO DEVELOPMENT BOARD (Part Number: EV10K72A)</a></li>
					</ul>
					<img src="./images/board.png" width="30%"; style="margin-left: 40px;">
				</article>
				<article>
					<header>
					<h3>2.3. 参考资料</h3>
					</header>
					<p>相关参考资料如下。</p>
					<ul>
					<li><a href="https://www.microchip.com/en-us/product/PIC24FJ64GU205" target="_blank">PIC24FJ64GU205 Data Sheet</a></li>
					<li><a href="http://ww1.microchip.com/downloads/en/DeviceDoc/70005156b.pdf" target="_blank">dsPIC33/PIC24 FRM, Dual Partition Flash Program Memory</a></li>
					<li><a href="https://www.microchip.com/en-us/development-tool/EV10K72A" target="_blank">PIC24FJ64GU205 Curiosity Development Board Nano User Guide</a></li>
					<li><a href="https://mu.microchip.com/16-bit-bootloaders-using-mcc-device-side-btl2-sc" target="_blank">MU Courses: 16-Bit Bootloaders Using MCC</a></li>
					</ul>
				</article>
			</section>
			
			<section>
				<h2>3. 自举程序工程创建</h2>
				<article>
					<header>
						<h3>3.1. 基于interrupt_remap_method文件夹下的工程修改，在16位bootloader设置界面勾选“Code Protect Bootloader”，选择代码保护模式，也就是使能应用程序用备用中断向量表。</h3>
					</header>
					<img src="./images/boot_setup1.png" width="80%">
				</article>
				<article>
					<header>
						<h3>3.2. 因为使能了应用程序用备用中断向量表，所以要对Boot段进行代码保护，同时也将配置字段代码进行保护。所以后续在建立应用程序工程时，相关代码保护设置要一致。。</h3>
					</header>
					<img src="./images/boot_setup2.png" width="80%">
				</article>
				<article>
					<header>
						<h3>3.3. 点击"Generate"按钮，生成代码。</h3>
					</header>
					<img src="./images/boot_setup3.png" width="80%">
					<img src="./images/boot_setup3_1.png" width="80%">
				</article>
				<article>
					<header>
						<h3>3.4. 对工程做如下配置，同时屏蔽boot_code_protec.c中错误警告代码段，否则编译会报错误告警。</h3>
					</header>
					<img src="./images/boot_setup4.png" width="80%">
				</article>
				<article>
					<header>
						<h3>3.5. 编译bootloader工程，编译成功完成bootloader工程创建。</h3>
					</header>
					<img src="./images/boot_setup5.png" width="80%">
				</article>
			</section>
			
			<section>
				<h2>4. 应用程序工程创建</h2>
				<article>
					<header>
						<h3>4.1. 同样基于interrupt_remap_method文件夹下的工程修改。和自举程序工程一样，因使能了应用程序用备用中断向量表，所以要对Boot段和配置字段进行代码保护，相关设置和自举工程一致。</h3>
					</header>
					<img src="./images/app_setup0.png" width="20%">
				</article>
				<article>
					<header>
						<h3>4.2. 点击"Generate"按钮，生成代码。</h3>
					</header>
					<img src="./images/app_setup1.png" width="80%">
				</article>
				<article>
					<header>
						<h3>4.3. 对工程做如下配置，同时屏蔽app_code_protec.c中错误警告代码段，否则编译会报错误告警。</h3>
					</header>
					<img src="./images/app_setup2.png" width="80%">
				</article>
				<article>
					<header>
						<h3>4.4. 现在点击编译按钮，可发现工程编译成功。</h3>
					</header>
					<img src="./images/app_setup3.png" width="80%">
				</article>
			</section>

			<section>
				<h2>5. 串口升级实验验证</h2>
				<article>
					<header>
						<h3>5.1. 桌面实验平台搭建如下。</h3>
					</header>
					<img src="./images/demo.jpg" width="30%">
				</article>
				<article>
					<header>
						<h3>5.2. 用usb线缆连接CNANO开发板的DEBUG USB口，烧录自举程序。烧录程序后可以看到CNANO开发板的LED0闪烁，闪烁周期100ms。</h3>
					</header>
					<img src="./images/verify_1.png" width="80%">
				</article>
				<article>
					<header>
						<h3>5.3. 明确CNANO开发板的串口号，并对scripts文件夹下的serial_upload.bat进行相应修改，之后点击该批处理文件完成升级工作。升级成功后，LED0闪烁速度变慢，周期变为500ms。</h3>
					</header>
					<img src="./images/verify_2.png" width="80%">
				</article>
				<article>
					<header>
						<h3>5.4. 若再次升级，需要拔掉USB线缆，接着按住CNANO开发板的SW0按键，然后在插入USB线缆，接着释放SW0按键，既可以再次重复5.3步骤。</h3>
					</header>
				</article>
				<article>
					<header>
						<h3>5.5. Application和Bootloader的Hex文件合并，运行scripts文件夹下的hex_merge_app_boot.bat。</h3>
					</header>
					<img src="./images/verify_3.png" width="80%">
				</article>
				<article>
					<header>
						<h3>5.6. 合并文件烧录，用USB线缆连接CNANO开发板，之后运行“MPLAB X IPE”烧录合并后的hex程序，烧录成功后LED0 500ms闪烁。若需要升级可以重复5.4步骤。</h3>
					</header>
					<img src="./images/verify_4.png" width="80%">
				</article>
			</section>
		</main>
	</body>
</html>